package task;

import java.util.Scanner;

/**
 * Creared with IntelliJ IDEA.
 * Description:内存可见性问题案例
 * User:yxd
 * Date:2022-03-29
 * Time:9:41
 */
public class Practice_3 {
    private volatile static int a = 0;//解决内存可见性问题,保证不会产生编译器的优化
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while(a == 0){

            }
            System.out.println("t线程结束");
        });
        t.start();
        Scanner input = new Scanner(System.in);
        System.out.println("请输入要修改的数:");
        a = input.nextInt();
        System.out.println("main线程结束");
    }
}
